package task

import (
	"context"
	"wx-dailydoer/common/errorutils"
	"wx-dailydoer/database/mysql"
	"wx-dailydoer/pb"
)

var ()

func List(ctx context.Context, request *pb.EmptyRequest) (*pb.ListOngoingTasksResponse, error) {

	tasks, err := mysql.OngoingTaskDAO.GetAll(ctx)
	if err != nil {
		return nil, err
	}

	res := []*pb.OngoingTask{}
	for _, task := range tasks {
		res = append(res, task.ConvertToDTO())
	}
	if len(res) != 0 {
		return &pb.ListOngoingTasksResponse{
			Total: int64(len(res)),
			Tasks: res,
		}, nil
	}
	return nil, errorutils.ErrNotFound
}
